package com.zyx.lock.controller;

import com.zyx.lock.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Yaxi.Zhang
 * @since 2022/9/10 15:03
 */
@RestController
public class TestController {
    @Value("${server.port}")
    private Integer serverPort;

    @Autowired
    private ITestService testService;

    @GetMapping("test/rlock")
    public String rlock(){
        testService.testRlock();
        return "port " + serverPort + " test";
    }

    @GetMapping("test/fairLock/{id}")
    public String fairLock(@PathVariable("id") Long id){
        testService.testFairLock(id);
        return "port " + serverPort + ", fairLock:" + id;
    }

    @GetMapping("test/read")
    public String readLock(){
        testService.testRead();
        return "port " + serverPort + " test read";
    }

    @GetMapping("test/write")
    public String writeLock(){
        testService.testWrite();
        return "port " + serverPort + " test write";
    }

    @GetMapping("test/semaphore")
    public String semaphore(){
        testService.testSemaphore();
        return "port " + serverPort + " test semaphore";
    }

    @GetMapping("test/latch")
    public String testLatch(){
        testService.testLatch();
        return "班长锁门。。。";
    }

    @GetMapping("test/countdown")
    public String testCountDown(){
        testService.testCountDown();
        return "出来了一位同学";
    }

}
